package com.bhs.sansong.ui.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bhs.sansong.R;
import com.bhs.sansong.adapter.FeeDetailAdapter;
import com.lxj.xpopup.impl.PartShadowPopupView;

/**
 * 付款方式和费用明细
 */
@SuppressLint("ViewConstructor")
public class PaymentDetailsPopWindows extends PartShadowPopupView {
    int gravity;
    private RadioButton mRbSpotPayment;
    private RadioButton mRbFreightCollectPaymento;
    public TextView mTvEstimatedCost;
    private RecyclerView mRvList;
    public FeeDetailAdapter mAdapter;
    private RadioGroup mRgPaymentMethod;

    public PaymentDetailsPopWindows(@NonNull Context context, int gravity) {
        super(context);
        this.gravity = gravity;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.layout_payment_details;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        LayoutParams params = (LayoutParams) findViewById(R.id.ll).getLayoutParams();
        params.gravity = gravity;
        initView();
        mAdapter = new FeeDetailAdapter();
        mRvList.setAdapter(mAdapter);
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initView() {
        findViewById(R.id.iv_close).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        mRbSpotPayment = findViewById(R.id.rb_spot_payment);
        mRbFreightCollectPaymento = findViewById(R.id.rb_freight_collect_paymento);
        mTvEstimatedCost = findViewById(R.id.tv_estimated_cost);
        mRbSpotPayment.setChecked(true);
        mRvList = findViewById(R.id.rv_list);
        mRgPaymentMethod = findViewById(R.id.rg_payment_method);
        mRgPaymentMethod.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (R.id.rb_spot_payment == i) {
                    listener.onClick("1", null);
                } else {
                    listener.onClick("2", null);
                }
            }
        });
    }

    private MyClickListener2 listener;

    public void setMyClickListener(@Nullable MyClickListener2 l) {
        this.listener = l;
    }
}

